<template>
  <div class="checkdistribution">
    <vue3-seamless-scroll
      :list="data"
      hover
      wheel
      :limitScrollNum="9"
      class="scroll"
    >
      <div
        class="checkdistribution-item"
        v-for="(item, index) in data"
        :key="index"
      >
        <el-tooltip
          class="box-item"
          effect="dark"
          :disabled="item.name.length <= 3"
          :content="item.name"
          placement="top-start"
        >
          <div
            class="item-city"
            :class="{
              'item-city-active': item.name.length > 3,
            }"
          >
            {{ item.name }}
          </div>
        </el-tooltip>
        <div class="item-all">
          <div
            class="danger"
            :style="{
              width:
                maxCheckCntItem.checkCnt == 0
                  ? 0
                  : (item.warnCnt / maxCheckCntItem.checkCnt) * 100 + '%',
            }"
          ></div>
          <div
            class="check"
            :style="{
              width:
                maxCheckCntItem.checkCnt == 0
                  ? 0
                  : (item.checkCnt / maxCheckCntItem.checkCnt) * 100 + '%',
            }"
          ></div>
        </div>
        <div class="item-Proportion">
          <span>{{ item.warnCnt }}</span>
          <span>/</span>
          <span>{{ item.checkCnt }}</span>
          <span>条</span>
        </div>
      </div>
    </vue3-seamless-scroll>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { Vue3SeamlessScroll } from "vue3-seamless-scroll";

let data = ref([]);
let maxCheckCntItem = 0;

const accept = (info) => {
  data.value = [];
  data.value = info.driveArea;
  // 使用 Array.prototype.reduce 方法找到 checkCnt 最大的对象
  maxCheckCntItem = data.value.reduce(function (prev, current) {
    return prev.checkCnt > current.checkCnt ? prev : current;
  });
};

defineExpose({ accept });
</script>

<style scoped lang="scss">
.checkdistribution {
  margin: 10px 15px;
  font-size: 14px;
  color: #ffffff;
  //   overflow-y: scroll;
  //   height: 25vh;
  height: 28vh;
  .scroll {
    height: 100%;
    width: 100%;
    overflow: hidden;
  }
  .checkdistribution-item {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 12px;
    .item-city {
      text-align: right;
      width: 20%;
      height: 100%;
      margin-right: 5px;
      overflow: hidden; /* 超出的内容隐藏 */
      text-overflow: ellipsis; /* 文字溢出部分显示为省略号 */
      white-space: nowrap; /* 强制在同一行内显示所有文本 */
    }
    .item-city-active {
      cursor: pointer;
    }
    .item-all {
      position: relative;
      width: 85%;
      height: 15px;
      background-color: #092032;
      .check {
        width: 50%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        background-color: #1898e2;
      }
      .danger {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        background-color: #f6c95c;
        z-index: 5;
      }
    }
    .item-Proportion {
      font-size: 12px;
      text-align: right;
      padding-left: 5px;
      width: 20%;
    }
  }
}
// .checkdistribution::-webkit-scrollbar {
//   display: none;
// }
</style>
